package kubayaxi.video.client.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import kubayaxi.video.client.service.IChannelService;
import kubayaxi.video.mybatis.auto.dao.ChannelMapper;
import kubayaxi.video.mybatis.auto.model.Channel;
import kubayaxi.video.mybatis.customize.dao.ChannelMeMapper;
import kubayaxi.video.mybatis.customize.model.channel.dto.ChannelVideoDTO;
import kubayaxi.video.mybatis.customize.model.channel.vo.ChannelVideoVO;
import kubayaxi.video.service.base.common.enums.DeleteEnum;
import kubayaxi.video.service.base.common.request.BaseRequest;
import kubayaxi.video.service.base.common.vo.CommonPageResult;
import kubayaxi.video.service.base.util.common.Asserts;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ChannelServiceImpl implements IChannelService {

    @Resource
    private ChannelMapper channelMapper;
    @Resource
    private ChannelMeMapper channelMeMapper;

    /**
     * 获取全部频道
     */
    @Override
    public List<Channel> allChannel() {
        return channelMapper.selectList(new LambdaQueryWrapper<Channel>()
                .eq(Channel::getDeleteStatus, DeleteEnum.NOT_DELETED.getCode())
                .orderByDesc(Channel::getSort));
    }

    /**
     * 获取频道相关视频
     */
    @Override
    public CommonPageResult<ChannelVideoVO> channelVideo(BaseRequest<ChannelVideoDTO> dto) {
        ChannelVideoDTO data = dto.getData();
        Asserts.isNotNull(data.getCId(),"频道id为空");
        Page page = new Page(dto.getPageNo(),dto.getPageSize());
        IPage<ChannelVideoVO> list = channelMeMapper.channelVideo(page, data);
        CommonPageResult<ChannelVideoVO> ans = new CommonPageResult<>();
        ans.setTotal(list.getTotal());
        ans.setList(list.getRecords());
        return ans;
    }
}
